  const app = getApp()
Page({
  data: {
    active: 0,
    active1:1,
    screenWidth: 0,
    imgwidth: 0,
    imgheight: 0,
    tabList: ["全部", '时令水果', '新鲜蔬菜', '肉禽蛋类', '海鲜水产', '酒水饮料','零食熟食', '粮油速食','纸品清洁'],
    goodsList: '',
    serverHost: app.config.serverHost,
    filterData: []
  },
  deletesale:function(e){
    var that = this;
    var goodsList = that.data.goodsList;
    var id = e.currentTarget.dataset.id;//获取当前长按图片下标
    console.log(id)
    wx.showModal({
      title: '提示',
      content: '确定要删除此商品吗？',
      success: function (res) {
        if (res.confirm) {
          app.api.deleteData('admin/goodslist', {id:id}, (res) => {
            that.setData({
              goodsList:res.data
            })
          })
        } else if (res.cancel) {
          return false;
        }
        that.setData({
          goodsList
        });
      }
    })
  },
  // 点击跳转到商品详情页
  toDetail: (e) => {
    let id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '../Goodslistdail/goods?id=' + id
    })
  },
  // 切换选中的标签栏状态
  changeActive: function (a) {
    let item = this.data.filterData
    let i = item.filter(e => {
      return a.detail.title == '全部' ? item : e.class == a.detail.title
    })
    this.setData({
      goodsList: i
    })
  },
  //点击tabbar
  onChange(event) {
    if (event.detail == "0") {
      wx.redirectTo({
        url: '../index',
      })
    } else if (event.detail == "2") {
      wx.redirectTo({
        url: '../order/order',
      })
    } else if (event.detail == "3"){
      wx.redirectTo({
        url: '../my/my',
      })
    }
  },
  onLoad(){
    var _this = this;
    wx.getSystemInfo({
      success: function (res) {
        _this.setData({
          screenWidth: res.windowWidth,
        });
      }
    })
  },
  onShow(){
    let _this = this
    new Promise((resolve,reject)=>{
    var phones={phone:wx.getStorageSync('phone')}
      app.api.getData('admin/goodslist', phones, (res) => {
        app.globalData.goodslist = res.data
        if (_this.callback) {
          _this.callback()
        }
        resolve(res.data)
      })
    })
    .then(data=>{
      _this.setData({
        goodsList: data,
        filterData:data
      })
    })
  },
  onUnload(){
    app.globalData.goodsListNumber = this.data.goodsList.length
  },
  imageLoad(){
    var screenW = this.data.screenWidth;
    var viewWidth = 320 * screenW / 750;
    var viewHeight = viewWidth;
    this.setData({
      imgwidth: viewWidth,
      imgheight: viewHeight
    })
  }
})